import sys
from PyQt5.QtWidgets import QApplication,QWidget,QFormLayout,QLineEdit
from PyQt5.QtCore import QRegExp  #正则表达式的类
from PyQt5.QtGui import QIntValidator,QDoubleValidator,QRegExpValidator #输入的要满足正则表达式

'''
该案例QLineEdit的文本有四种显示方式
1、Normal	正常显示，输入啥，显示啥，这是默认值
2、NoEcho	输入但不显示任何东西，暗戳戳的执行，不显示任何内容。这可能适用于密码，即使密码的长度也应保密
3、Password	密码格式显示
4、PasswordEchoOnEdit	编辑时显示输入的字符，否则显示大圆点。再次编辑会删除之前的内容
'''


class MyLineEdit(QLineEdit):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.line_edit1 = QLineEdit(self)
        self.line_edit2 = QLineEdit()
        self.line_edit3 = QLineEdit()
        self.line_edit4 = QLineEdit()

        self.line_edit1.setEchoMode(QLineEdit.Normal)
        self.line_edit2.setEchoMode(QLineEdit.NoEcho)
        self.line_edit3.setEchoMode(QLineEdit.Password)
        self.line_edit4.setEchoMode(QLineEdit.PasswordEchoOnEdit)

        self.line_edit1.setPlaceholderText("这是Normal格式的输入")
        self.line_edit2.setPlaceholderText("这是NoEcho格式的输入")
        self.line_edit3.setPlaceholderText("这是Password格式的输入")
        self.line_edit4.setPlaceholderText("这是PasswordEchoOnEdit格式的输入")

        #设置布局
        self.formLayout = QFormLayout()

        self.formLayout.addRow("Normal", self.line_edit1)
        self.formLayout.addRow("NoEcho", self.line_edit2)
        self.formLayout.addRow("Password", self.line_edit3)
        self.formLayout.addRow("PasswordEchoOnEdit", self.line_edit4)

        self.setLayout(self.formLayout)


        #进阶功能:实现检验输入,范围0-99
        intValidator = QIntValidator()
        intValidator.setRange(0,100)
        self.line_edit1.setValidator(intValidator)



if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = MyLineEdit()
    widget.setGeometry(100, 100, 400, 400)
    widget.show()

    sys.exit(app.exec_())